import axios from 'axios'
import { baseURL } from '@/config'

const instance = axios.create({
  baseURL,
  timeout: 6000
})

// add request interceptors
instance.interceptors.request.use(config => {
  window.progress.start()
  // before request config
  return config
}, (error) => {
  return Promise.reject(error)
})

// add response interceptors
instance.interceptors.response.use(response => {
  window.progress.done()
  // before response config
  // 401 ----- 登录过期----------------------
  // window.storage.remove('token')
  return Promise.resolve(response)
}, (error) => {
  console.log(error)
  return Promise.reject(error)
})

export const get = (url, params) => instance.get(url, params)
export const post = (url, data) => instance.post(url, data)